home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Linux / Linux Mint 3.0 Light / LinuxMint-3.0-Light.iso / casper / filesystem.squashfs / usr / lib / sunbird / run-mozilla.sh < prev    next >
Encoding:
Linux/UNIX/POSIX Shell Script  |  2007-05-23  |  11.4 KB  |  454 lines

  1. #!/bin/sh
  2. #
  3. # ***** BEGIN LICENSE BLOCK *****
  4. # Version: MPL 1.1/GPL 2.0/LGPL 2.1
  5. #
  6. # The contents of this file are subject to the Mozilla Public License Version
  7. # 1.1 (the "License"); you may not use this file except in compliance with
  8. # the License. You may obtain a copy of the License at
  9. # http://www.mozilla.org/MPL/
  10. #
  11. # Software distributed under the License is distributed on an "AS IS" basis,
  12. # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  13. # for the specific language governing rights and limitations under the
  14. # License.
  15. #
  16. # The Original Code is mozilla.org code.
  17. #
  18. # The Initial Developer of the Original Code is
  19. # Netscape Communications Corporation.
  20. # Portions created by the Initial Developer are Copyright (C) 1998
  21. # the Initial Developer. All Rights Reserved.
  22. #
  23. # Contributor(s):
  24. #
  25. # Alternatively, the contents of this file may be used under the terms of
  26. # either of the GNU General Public License Version 2 or later (the "GPL"),
  27. # or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
  28. # in which case the provisions of the GPL or the LGPL are applicable instead
  29. # of those above. If you wish to allow use of your version of this file only
  30. # under the terms of either the GPL or the LGPL, and not to allow others to
  31. # use your version of this file under the terms of the MPL, indicate your
  32. # decision by deleting the provisions above and replace them with the notice
  33. # and other provisions required by the GPL or the LGPL. If you do not delete
  34. # the provisions above, a recipient may use your version of this file under
  35. # the terms of any one of the MPL, the GPL or the LGPL.
  36. #
  37. # ***** END LICENSE BLOCK *****
  38. cmdname=`basename "$0"`
  39. MOZ_DIST_BIN=`dirname "$0"`
  40. MOZ_DEFAULT_NAME="./${cmdname}-bin"
  41. MOZ_APPRUNNER_NAME="./mozilla-bin"
  42. MOZ_VIEWER_NAME="./viewer"
  43. MOZ_PROGRAM=""
  44.  
  45. exitcode=0
  46. #
  47. ##
  48. ## Functions
  49. ##
  50. ##########################################################################
  51. moz_usage()
  52. {
  53. echo "Usage:  ${cmdname} [options] [program]"
  54. echo ""
  55. echo "  options:"
  56. echo ""
  57. echo "    -g                   Run in debugger."
  58. echo "    --debug"
  59. echo ""
  60. echo "    -d debugger          Debugger to use."
  61. echo "    --debugger debugger"
  62. echo ""
  63. echo "  Examples:"
  64. echo ""
  65. echo "  Run the viewer"
  66. echo ""
  67. echo "    ${cmdname} viewer"
  68. echo ""
  69. echo "  Run the mozilla-bin binary"
  70. echo ""
  71. echo "    ${cmdname} mozilla-bin"
  72. echo ""
  73. echo "  Debug the viewer in a debugger"
  74. echo ""
  75. echo "    ${cmdname} -g viewer"
  76. echo ""
  77. echo "  Debug the mozilla-bin binary in gdb"
  78. echo ""
  79. echo "    ${cmdname} -g mozilla-bin -d gdb"
  80. echo ""
  81.     return 0
  82. }
  83. ##########################################################################
  84. moz_bail()
  85. {
  86.     message=$1
  87.     echo
  88.     echo "$cmdname: $message"
  89.     echo
  90.     exit 1
  91. }
  92. ##########################################################################
  93. moz_test_binary()
  94. {
  95.     binary=$1
  96.     if [ -f "$binary" ]
  97.     then
  98.         if [ -x "$binary" ]
  99.         then
  100.             return 1
  101.         fi
  102.     fi
  103.     return 0
  104. }
  105. ##########################################################################
  106. moz_get_debugger()
  107. {
  108.     debuggers="ddd gdb dbx bdb"
  109.     debugger="notfound"
  110.     done="no"
  111.     for d in $debuggers
  112.     do
  113.         moz_test_binary /bin/type
  114.         if [ $? -eq 1 ]
  115.         then
  116.             dpath=`type ${d} | awk '{print $3;}' | sed -e 's/\.$//'`    
  117.         else     
  118.             dpath=`which ${d}`    
  119.         fi
  120.         if [ -x "$dpath" ]
  121.         then
  122.             debugger=$dpath
  123.             break
  124.         fi
  125.     done
  126.     echo $debugger
  127.     return 0
  128. }
  129. ##########################################################################
  130. moz_run_program()
  131. {
  132.     prog=$MOZ_PROGRAM
  133.     ##
  134.     ## Make sure the program is executable
  135.     ##
  136.     if [ ! -x "$prog" ]
  137.     then
  138.         moz_bail "Cannot execute $prog."
  139.     fi
  140.     ##
  141.     ## Use md5sum to crc a core file.  If md5sum is not found on the system,
  142.     ## then don't debug core files.
  143.     ##
  144.     moz_test_binary /bin/type
  145.     if [ $? -eq 1 ]
  146.     then
  147.         crc_prog=`type md5sum 2>/dev/null | awk '{print $3;}' 2>/dev/null | sed -e 's/\.$//'`
  148.     else
  149.         crc_prog=`which md5sum 2>/dev/null`
  150.     fi
  151.     if [ -x "$crc_prog" ]
  152.     then
  153.         DEBUG_CORE_FILES=1
  154.     fi
  155.     if [ "$DEBUG_CORE_FILES" ]
  156.     then
  157.         crc_old=
  158.         if [ -f core ]
  159.         then
  160.             crc_old=`$crc_prog core | awk '{print $1;}' `
  161.         fi
  162.     fi
  163.     ##
  164.     ## Run the program
  165.     ##
  166.     "$prog" ${1+"$@"}
  167.     exitcode=$?
  168.     if [ "$DEBUG_CORE_FILES" ]
  169.     then
  170.         if [ -f core ]
  171.         then
  172.             crc_new=`$crc_prog core | awk '{print $1;}' `
  173.         fi
  174.     fi
  175.     if [ "$crc_old" != "$crc_new" ]
  176.     then
  177.         printf "\n\nOh no!  %s just dumped a core file.\n\n" $prog
  178.         printf "Do you want to debug this ? "
  179.         printf "You need a lot of memory for this, so watch out ? [y/n] "
  180.         read ans
  181.         if [ "$ans" = "y" ]
  182.         then
  183.             debugger=`moz_get_debugger`
  184.             if [ -x "$debugger" ]
  185.             then
  186.                 echo "$debugger $prog core"
  187.  
  188.                 # See http://www.mozilla.org/unix/debugging-faq.html
  189.                 # For why LD_BIND_NOW is needed
  190.                 LD_BIND_NOW=1; export LD_BIND_NOW
  191.  
  192.                 $debugger "$prog" core
  193.             else
  194.                 echo "Could not find a debugger on your system."
  195.             fi
  196.         fi
  197.     fi
  198. }
  199. ##########################################################################
  200. moz_debug_program()
  201. {
  202.     prog=$MOZ_PROGRAM
  203.     ##
  204.     ## Make sure the program is executable
  205.     ##
  206.     if [ ! -x "$prog" ]
  207.     then
  208.         moz_bail "Cannot execute $prog."
  209.     fi
  210.     if [ -n "$moz_debugger" ]
  211.     then
  212.         moz_test_binary /bin/type
  213.         if [ $? -eq 1 ]
  214.         then    
  215.             debugger=`type $moz_debugger | awk '{print $3;}' | sed -e 's/\.$//'` 
  216.         else
  217.             debugger=`which $moz_debugger` 
  218.         fi    
  219.     else
  220.         debugger=`moz_get_debugger`
  221.     fi
  222.     if [ -x "$debugger" ] 
  223.     then
  224.         tmpfile=`mktemp /tmp/mozargs.XXXXXX` || { echo "Cannot create temporary file" >&2; exit 1; }
  225.         trap " [ -f \"$tmpfile\" ] && /bin/rm -f -- \"$tmpfile\"" 0 1 2 3 13 15
  226.         # echo -n isn't portable, so pipe through perl -pe chomp instead
  227.         echo "set args" | perl -pe 'chomp' > $tmpfile
  228.         for PARAM in "$@"
  229.         do
  230.             echo " '$PARAM'" | perl -pe 'chomp' >> $tmpfile
  231.         done
  232.         echo >> $tmpfile
  233. # If you are not using ddd, gdb and know of a way to convey the arguments 
  234. # over to the prog then add that here- Gagan Saksena 03/15/00
  235.         case `basename $debugger` in
  236.             gdb) echo "$debugger $prog -x $tmpfile"
  237.                 $debugger "$prog" -x $tmpfile
  238.         exitcode=$?
  239.                 ;;
  240.             ddd) echo "$debugger --debugger \"gdb -x $tmpfile\" $prog"
  241.                 $debugger --debugger "gdb -x $tmpfile" "$prog"
  242.         exitcode=$?
  243.                 ;;
  244.             *) echo "$debugger $prog ${1+"$@"}"
  245.                 $debugger "$prog" ${1+"$@"}
  246.         exitcode=$?
  247.                 ;;
  248.         esac
  249.     else
  250.         echo "Could not find a debugger on your system." 
  251.     fi
  252. }
  253. ##########################################################################
  254. ##
  255. ## Command line arg defaults
  256. ##
  257. moz_debug=0
  258. moz_debugger=""
  259. #
  260. ##
  261. ## Parse the command line
  262. ##
  263. while [ $# -gt 0 ]
  264. do
  265.   case $1 in
  266.     -g | --debug)
  267.       moz_debug=1
  268.       shift
  269.       ;;
  270.     -d | --debugger)
  271.       moz_debugger=$2;
  272.       if [ "${moz_debugger}" != "" ]; then
  273.     shift 2
  274.       else
  275.         echo "-d requires an argument"
  276.         exit 1
  277.       fi
  278.       ;;
  279.     *)
  280.       break;
  281.       ;;
  282.   esac
  283. done
  284. #
  285. ##
  286. ## Program name given in $1
  287. ##
  288. if [ $# -gt 0 ]
  289. then
  290.     MOZ_PROGRAM=$1
  291.     shift
  292. fi
  293. ##
  294. ## Program not given, try to guess a default
  295. ##
  296. if [ -z "$MOZ_PROGRAM" ]
  297. then
  298.     ##
  299.     ## Try this script's name with '-bin' appended
  300.     ##
  301.     if [ -x "$MOZ_DEFAULT_NAME" ]
  302.     then
  303.         MOZ_PROGRAM=$MOZ_DEFAULT_NAME
  304.     ## Try viewer (this should be deprecated)
  305.     ## 
  306.     elif [ -x "$MOZ_VIEWER_NAME" ]
  307.     then
  308.         MOZ_PROGRAM=$MOZ_VIEWER_NAME
  309.     ##
  310.     ## Try mozilla-bin
  311.     ## 
  312.     elif [ -x "$MOZ_APPRUNNER_NAME" ]
  313.     then
  314.         MOZ_PROGRAM=$MOZ_APPRUNNER_NAME
  315.     fi
  316. fi
  317. #
  318. #
  319. ##
  320. ## Make sure the program is executable
  321. ##
  322. if [ ! -x "$MOZ_PROGRAM" ]
  323. then
  324.     moz_bail "Cannot execute $MOZ_PROGRAM."
  325. fi
  326. #
  327. ##
  328. ## Set MOZILLA_FIVE_HOME
  329. ##
  330. MOZILLA_FIVE_HOME=$MOZ_DIST_BIN
  331.  
  332. if [ -z "$MRE_HOME" ]; then
  333.     MRE_HOME=$MOZILLA_FIVE_HOME
  334. fi
  335. ##
  336. ## Set LD_LIBRARY_PATH
  337. ##
  338. ## On Solaris we use $ORIGIN (set in RUNPATH) instead of LD_LIBRARY_PATH 
  339. ## to locate shared libraries. 
  340. ##
  341. ## When a shared library is a symbolic link, $ORIGIN will be replaced with
  342. ## the real path (i.e., what the symbolic link points to) by the runtime
  343. ## linker.  For example, if dist/bin/libmozjs.so is a symbolic link to
  344. ## js/src/libmozjs.so, $ORIGIN will be "js/src" instead of "dist/bin".
  345. ## So the runtime linker will use "js/src" NOT "dist/bin" to locate the
  346. ## other shared libraries that libmozjs.so depends on.  This only happens
  347. ## when a user (developer) tries to start firefox, thunderbird, or seamonkey
  348. ## under dist/bin. To solve the problem, we should rely on LD_LIBRARY_PATH
  349. ## to locate shared libraries.
  350. ##
  351. ## Note: 
  352. ##  We choose libmozjs.so as a representative shared library. If it is 
  353. ##  a symbolic link, all other shared libraries are symbolic links also.
  354. if [ `uname -s` != "SunOS" -o -h "$MOZ_DIST_BIN/libmozjs.so" ]
  355. then
  356.     LD_LIBRARY_PATH=${MOZ_DIST_BIN}:${MOZ_DIST_BIN}/plugins:${MRE_HOME}${LD_LIBRARY_PATH+":$LD_LIBRARY_PATH"}
  357. fi 
  358.  
  359. if [ -n "$LD_LIBRARYN32_PATH" ]
  360. then
  361.     LD_LIBRARYN32_PATH=${MOZ_DIST_BIN}:${MOZ_DIST_BIN}/plugins:${MRE_HOME}${LD_LIBRARYN32_PATH+":$LD_LIBRARYN32_PATH"}
  362. fi
  363. if [ -n "$LD_LIBRARYN64_PATH" ]
  364. then
  365.     LD_LIBRARYN64_PATH=${MOZ_DIST_BIN}:${MOZ_DIST_BIN}/plugins:${MRE_HOME}${LD_LIBRARYN64_PATH+":$LD_LIBRARYN64_PATH"}
  366. fi
  367. if [ -n "$LD_LIBRARY_PATH_64" ]; then
  368.     LD_LIBRARY_PATH_64=${MOZ_DIST_BIN}:${MOZ_DIST_BIN}/plugins:${MRE_HOME}${LD_LIBRARY_PATH_64+":$LD_LIBRARY_PATH_64"}
  369. fi
  370. #
  371. #
  372. ## Set SHLIB_PATH for HPUX
  373. SHLIB_PATH=${MOZ_DIST_BIN}:${MRE_HOME}${SHLIB_PATH+":$SHLIB_PATH"}
  374. #
  375. ## Set LIBPATH for AIX
  376. LIBPATH=${MOZ_DIST_BIN}:${MRE_HOME}${LIBPATH+":$LIBPATH"}
  377. #
  378. ## Set DYLD_LIBRARY_PATH for Mac OS X (Darwin)
  379. DYLD_LIBRARY_PATH=${MOZ_DIST_BIN}:${MRE_HOME}${DYLD_LIBRARY_PATH+":$DYLD_LIBRARY_PATH"}
  380. #
  381. ## Set LIBRARY_PATH for BeOS
  382. LIBRARY_PATH=${MOZ_DIST_BIN}:${MOZ_DIST_BIN}/components:${MRE_HOME}${LIBRARY_PATH+":$LIBRARY_PATH"}
  383. #
  384. ## Set ADDON_PATH for BeOS
  385. ADDON_PATH=${MOZ_DIST_BIN}${ADDON_PATH+":$ADDON_PATH"}
  386. #
  387. ## Solaris Xserver(Xsun) tuning - use shared memory transport if available
  388. if [ "$XSUNTRANSPORT" = "" ]
  389. then 
  390.         XSUNTRANSPORT="shmem" 
  391.         XSUNSMESIZE="512"
  392.         export XSUNTRANSPORT XSUNSMESIZE
  393. fi
  394. ## Populate XPSERVERLIST if it was not set yet
  395. if [ "$XPSERVERLIST" = "" ]
  396. then
  397.     if [ -f /etc/init.d/xprint ] ; then
  398.         XPSERVERLIST="`/bin/sh /etc/init.d/xprint get_xpserverlist`"
  399.         if [ "$XPSERVERLIST" != "" ] ; then
  400.             export XPSERVERLIST
  401.         fi
  402.     fi
  403. fi
  404.  
  405. if [ "$moz_debug" -eq 1 ]
  406. then
  407.   echo "MOZILLA_FIVE_HOME=$MOZILLA_FIVE_HOME"
  408.   echo "  LD_LIBRARY_PATH=$LD_LIBRARY_PATH"
  409.   if [ -n "$LD_LIBRARYN32_PATH" ]
  410.   then
  411.       echo "LD_LIBRARYN32_PATH=$LD_LIBRARYN32_PATH"
  412.   fi
  413.   if [ -n "$LD_LIBRARYN64_PATH" ]
  414.   then
  415.       echo "LD_LIBRARYN64_PATH=$LD_LIBRARYN64_PATH"
  416.   fi
  417.   if [ -n "$LD_LIBRARY_PATH_64" ]; then
  418.       echo "LD_LIBRARY_PATH_64=$LD_LIBRARY_PATH_64"
  419.   fi
  420.   if [ -n "$DISPLAY" ]; then
  421.        echo "DISPLAY=$DISPLAY"
  422.   fi
  423.   if [ -n "$FONTCONFIG_PATH" ]; then
  424.     echo "FONTCONFIG_PATH=$FONTCONFIG_PATH"
  425.   fi
  426.   if [ -n "$XPSERVERLIST" ]; then
  427.        echo "XPSERVERLIST=$XPSERVERLIST"
  428.   fi
  429.   if [ -n "$MOZILLA_POSTSCRIPT_PRINTER_LIST" ]; then
  430.        echo "MOZILLA_POSTSCRIPT_PRINTER_LIST=$MOZILLA_POSTSCRIPT_PRINTER_LIST"
  431.   fi
  432.   echo "DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH"
  433.   echo "     LIBRARY_PATH=$LIBRARY_PATH"
  434.   echo "       SHLIB_PATH=$SHLIB_PATH"
  435.   echo "          LIBPATH=$LIBPATH"
  436.   echo "       ADDON_PATH=$ADDON_PATH"
  437.   echo "      MOZ_PROGRAM=$MOZ_PROGRAM"
  438.   echo "      MOZ_TOOLKIT=$MOZ_TOOLKIT"
  439.   echo "        moz_debug=$moz_debug"
  440.   echo "     moz_debugger=$moz_debugger"
  441. fi
  442. #
  443. export MOZILLA_FIVE_HOME LD_LIBRARY_PATH
  444. export SHLIB_PATH LIBPATH LIBRARY_PATH ADDON_PATH DYLD_LIBRARY_PATH
  445.  
  446. if [ $moz_debug -eq 1 ]
  447. then
  448.     moz_debug_program ${1+"$@"}
  449. else
  450.     moz_run_program ${1+"$@"}
  451. fi
  452.  
  453. exit $exitcode
  454.